/*******************************************************************************
				TABLE 1
*******************************************************************************/

*WAGE IV, COWORKERS
*TABLE 1, PANEL A, ROW 1
cap{
use "$data/base WAGE IV companies.dta", clear

global xi edad edad2 sexo anos_educ puntaje lnw
global xg m_l_edad m_l_sexo m_l_puntaje m_l_anos_educ

local dep l_net
local iv z_lnet
eststo clear
		
*1. FIRST STAGE:
qui reg `dep' $xi $xg `iv', cluster(rut_emp)
	eststo first_lnet_1012
	cap test z_lnet
	estadd scalar Ft = r(F)
	
*2. REDUCED FORM:
qui reg sej2012 $xi $xg `iv', cluster(rut_emp)
	eststo rflnet_1012
	
*3. SECOND STAGE:
qui ivreg sej2012 $xi $xg (`dep' = `iv'), cluster(rut_emp) 
	eststo ivlnet_1012
	}
	
esttab first_lnet_1012 rflnet_1012 ivlnet_1012, ///
	b(%6.4fc) se(%6.4fc) star(* 0.1 ** 0.05 *** 0.01) ///
	stats(N Ft, fmt(%8.0fc %8.1fc) labels(Observations F))  ///
	brackets coeflabels(l_net "Endogenous" z_lnet "Instrument") ///
	keep(`dep' `iv') mtitles("First Stage" "Reduced Form" "TSLS") ///
	title("Table 1 Panel A. Wage Instrument: Effect of peers' adoption in 2009 on YES adoption during 2010-2012") 
clear

********************************************************************************

*WAGE IV, CLASSMATES
*TABLE 1, PANEL A, ROW 2
cap{
use "$data/base WAGE IV schools.dta", clear

global xi edad edad2 sexo anos_educ puntaje lnw
global xg m_s_edad m_s_sexo m_s_puntaje m_s_anos_educ 

local dep s_net
local iv z_snet
eststo clear

*1. FIRST STAGE:
qui reg `dep' $xi $xg `iv', cluster(rbd)
	eststo first
	test z_snet
	estadd scalar Ft = r(F)

*2. REDUCED FORM:
qui reg sej2012 $xi $xg `iv', cluster(rbd)
	eststo rf

*3. SECOND STAGE:
qui ivreg sej2012 $xi $xg (`dep' = `iv'), cluster(rbd)
	eststo iv
	}
esttab first rf iv, keep(z_snet s_net) ///
	mtitles("First Stage" "Reduced Form" "TSLS") ///
	b(%6.4fc) se(%6.4fc) star(* 0.1 ** 0.05 *** 0.01) ///
	stats(N Ft, fmt(%8.0fc %8.1fc) labels(Observations F)) brackets ///
	coeflabels(s_net "Endogenous" z_snet "Instrument") /// 
	title("Table 1 Panel A. Wage Instrument: Effect of peers' adoption in 2009 on YES adoption during 2010-2012") 
clear

********************************************************************************

*AGE IV, COWORKERS
*TABLE 1, PANEL B
cap{
use "$data/base AGE IV.dta", clear

global xi edad edad2 sexo puntaje lnw anos_educ
global xg m_l_sexo m_l_puntaje m_l_anos_educ m_l_lnw

local dep lnet
local iv zlnet
eststo clear

*1. FIRST STAGE:
qui reg `dep' $xi $xg `iv', cluster(rut_emp)
	eststo first_firm
	test zlnet
	estadd scalar Ft = r(F)

*2. REDUCED FORM:
qui reg sej2012 $xi $xg `iv', cluster(rut_emp)
	eststo rf_firm

*3. SECOND STAGE:
qui ivreg sej2012 $xi $xg (`dep' = `iv'), cluster(rut_emp)
	eststo iv_firm
}
esttab first_firm rf_firm iv_firm, ///
	b(%6.4fc) se(%6.4fc) star(* 0.1 ** 0.05 *** 0.01) ///
	stats(N Ft, fmt(%8.0fc %8.1fc) labels(Observations F))  ///
	brackets coeflabels(`dep' "Endogenous" `iv' "Instrument") ///
	keep(`dep' `iv') mtitles("First Stage" "Reduced Form" "TSLS") ///
	title("Table 1 Panel B. Age Instrument: Effect of peers' adoption in 2009 on YES adoption during 2010-2012") 
clear
